<?php

// Set any router rules here
router::setRule( 'twitterAPI', 'tweets/one', 'twitter/one', 'module' );
router::setRule( 'voucher',      'voucher',   'liriope/redirect/url/'.urlencode(wufoo('z1f3jqx11a2pvt4')));

// set some configuration settings
c::set('twitter.accessToken', "AAAAAAAAAAAAAAAAAAAAAGSjRQAAAAAANY6h%2FYnT9aWKx%2FMiu451tUNl4pk%3DY6IV4mIV72cydbqHLtir565zG1otMOZXNdnofd6IlU");

c::set('students.middle.school.times', '6:30&mdash;8:00pm');
c::set('students.high.school.times',   '4:00&mdash;5:30pm');

function shortNRHCdate($date) { return NRHCdate($date, 0); }
function mediumNRHCdate($date) { return NRHCdate($date, 2); }
function fullNRHCdate($date) { return NRHCdate($date, 1); }
function NRHCdate( $date=NULL, $full=TRUE ) {
  if($date === NULL) return NULL;

  // formats the given date
  $full_format = "l, F j, Y";
  $medium_format = "l, F j";
  $short_format = "F j";
  $format = $full ? $full_format : $medium_format;
  switch($full) {
    case 0:
      $format = $short_format;
      break;
    case 2:
      $format = $medium_format;
      break;
    case 1:
    default:
      $format = $full_format;
      break;
  }

  // accept an array and combine with &ndash;
  if(is_array($date)) {
    $return = array();
    $c = 1;
    $count = count($date);
    foreach($date as $d) {
      if($c++ === $count) $return[] = date($full_format, strtotime($d));
      else $return[] = date($medium_format, strtotime($d));
    }
    return implode('–', $return);
  }
  return date( $format, strtotime( $date ));
}

function linkVerse($verse=NULL) {
  if( $verse===NULL ) return;
  $biblegateway_query = "http://www.biblegateway.com/passage/?search=%s&version=ESV";
  $anchor_tag = '<a href="%s" target="_blank">%s</a>';
  $query = urlencode( $verse );
  return sprintf( $anchor_tag, sprintf( $biblegateway_query, $query ), $verse );
}

function form($name) {
  $url="http://nrhc-pages.northrockhill.com/forms/index.php?form=%s";
  return sprintf($url, $name);
}

function wufoo($name) {
    $url = 'https://northrockhill.wufoo.com/forms/%s/';
    return sprintf($url, $name);
}

// gt()
// Google Tracking code
// used in the enews links
//
// @param  string  $content The descriptor of the type of item wrapped by the anchor tag [link, chip, readmore]
// @return string  Returns a list of query params for an anchor tag to follow the ? (not included)
//
function gt( $content='link', $return=FALSE ) {
  $code = "utm_source=newsletter&amp;utm_medium=email&amp;utm_content=%s&amp;utm_campaign=eNews";
  if(!$return) echo sprintf($code, $content);
  return sprintf($code, $content);
}

?>
